package com.nine.news.modular.user.controller;

import com.nine.news.constants.SystemConfig;
import com.nine.news.modular.annation.Token;
import com.nine.news.modular.user.param.UserFindPasswdParam;
import com.nine.news.modular.user.param.UserLoginCodeParam;
import com.nine.news.modular.user.param.UserLoginNameParam;
import com.nine.news.modular.user.param.UserLogonParam;
import com.nine.news.modular.user.service.UserService;
import com.nine.news.response.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author: szhan
 * @Date: 2023/03/22/8:03 PM
 * @Description:
 */
@RestController
@RequestMapping("/api/user")
@Api(tags = "用户模块")
public class UserController {
    @Resource
    private UserService userService;

    @GetMapping("all")
    @ApiOperation("查询全部")
    public R all() {
        return userService.all();
    }

    @GetMapping("checkname")
    @ApiOperation("校验用户名")
    public R checkName(@RequestParam("name") String name) {
        return userService.checkName(name);
    }

    @GetMapping("checkphone")
    @ApiOperation("校验手机号")
    public R checkPhone(@RequestParam("phone") String phone) {
        return userService.checkPhone(phone);
    }

    @PostMapping("findpass")
    @ApiOperation("找回密码")
    public R findPass(@RequestBody UserFindPasswdParam param) {
        return userService.findPass(param);
    }

    @PostMapping("logincode")
    @ApiOperation("验证码登陆")
    public R loginCode(@RequestBody UserLoginCodeParam param) {
        return userService.loginCode(param);
    }

    @PostMapping("loginname")
    @ApiOperation("用户名密码登录")
    public R loginName(@RequestBody UserLoginNameParam param) {
        return userService.loginName(param);
    }

    @Token
    @PostMapping("loginout")
    @ApiOperation("退出登陆")
    public R loginOut(HttpServletRequest request) {
        return userService.loginOut(request.getHeader(SystemConfig.HEADER_AUTH));
    }

    @PostMapping("register")
    @ApiOperation("注册")
    public R register(@RequestBody UserLogonParam param) {
        return userService.register(param);
    }

    @Token
    @PostMapping("updatepass")
    @ApiOperation("密码修改")
    public R updatePass(@RequestParam("password") String password,HttpServletRequest request) {
        return userService.updatePass(request.getHeader(SystemConfig.HEADER_AUTH),password);
    }


}
